package TEST;

import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

interface IntegerStack {
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();
}
public class Main1 implements IntegerStack{
	
	private List<Integer> arrList = new ArrayList<Integer>();
	
	public Integer push(Integer item) {
		if(item==null) return null;
		arrList.add(item);
		return item;
	}

	public Integer pop() {
		if(arrList.size()==0)
			return null;
		else
			return arrList.remove(arrList.size()-1);
		}
	

	public Integer peek() {
		if(arrList.size()==0)
			return null;
		else{
			return arrList.get(arrList.size()-1);
		}
	}

	public boolean empty() {
		if(arrList.size()==0)
		return true;
		else
		return false;
	}

	public int size() {
		return arrList.size();
	}
	 public String toString(){
		 return arrList.toString();
	 }
	 
	 public static void main(String[] args) {
		 Scanner sc=new Scanner(System.in);
		 Main1 arr=new Main1();
		 int m=sc.nextInt();
		 for(int i=0;i<m;i++){
			 int m1=sc.nextInt();
			 arr.push(m1);
			 System.out.println(m1);
		 }
		 System.out.println(arr.peek()+","+arr.empty()+","+arr.size());
		 System.out.println(arr.toString());
		 
		 int x=sc.nextInt();
		 for(int i=0;i<x;i++){
			 System.out.println(arr.peek());
			 arr.pop();
		 }
		 System.out.println(arr.peek()+","+arr.empty()+","+arr.size());
		 System.out.println(arr.toString());	 
	 }
	 
}



